<%-- 
    Document   : detail_staff_visit
    Created on : Apr 28, 2014, 4:25:57 PM
    Author     : Mansur
--%>

<%@ include file="/WEB-INF/jsp/include/page_header.jspf" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>.: Ship Visit :.</title>    
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.blockUI.js"></script>   
        <script type="text/javascript"> 
            function checkingSubmit(){
                var result = true;
                var c = 0;
                var radios = document.getElementsByName('statusApproval');
                for(var i = 0; i< radios.length; i++){
                    if(radios[i].checked){
                        if(radios[i].value === 'R' && $('#rejectnote').val() === ''){
                            alert('Comments must be filled if Approval is rejected.');
                            result = false;
                        }
                        c++;
                    }
                }
                if(c === 0){
                    alert('Approval must be filled before submit');
                    result = false;
                }
                return result;
            }
            
            function back(id,status,cyear){
                var s = null;
                if(status === 'APPROVED'){
                    s = 'A';
                }
                if(status === 'REJECTED'){
                    s = 'R';
                }
                var frm = document.forms.form1;
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?listStaffVisited&idStaff='+id+'&status='+s+'&currentYear='+cyear;
                frm.action = url;
                frm.submit();
            }
        </script>
        <script type="text/javascript">
            function popupWin(id) {
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?viewEditDocument&idVisit=' + id + '&flag=0';
                var left = (screen.width/2)-(1000/2);
                var top = (screen.height/2)-(1000/2);                
                var params = 'width=1000';
                params += ', height=1000';
                params += ', top=' + top;
                params += ', left=' + left;
                //params += ', fullscreen=yes';
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';                
                newwin = window.open(url, 'PopUp', params);
                if (window.focus) {
                    newwin.focus();
                }                
                return false;
            }
            
            function popupWinSub(id) {
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?viewEditDocumentSub&idVisitExtend=' + id + '&flag=0';
                var left = (screen.width/2)-(1000/2);
                var top = (screen.height/2)-(1000/2);                
                var params = 'width=1000';
                params += ', height=1000';
                params += ', top=' + top;
                params += ', left=' + left;
                //params += ', fullscreen=yes';
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';                
                newwin = window.open(url, 'PopUp', params);
                if (window.focus) {
                    newwin.focus();
                }                
                return false;
            }
        </script>
        <style>
            .validateTips { border: 1px solid transparent; padding: 0.3em; font-weight: bold; font-size: 10pt;}
            em {color: red}
            br {margin: -3em}
            .tableHeader { vertical-align: top; text-align: right; font-weight: bold; }
            .tableValue { vertical-align: top; text-align: left; }
        </style>
    </head>
    <body>
        <s:useActionBean beanclass="exatrez.stripes.util.ListUtil" var="list"/>
        <s:useActionBean beanclass="exatrez.stripes.util.ShipVisit3ListUtil" var="sv3list"/>
        <s:form beanclass="exatrez.stripes.action.ShipVisit3FlowAction" name="form1">
            <s:hidden name="shipVisit3Id" />
            <s:hidden name="counterId" />
            <div>
                <fieldset>                    
                    <div id="page-title">
                        <span class="title">Ship Visit</span>
                    </div>
                    <div style="align: center">
                        <span class="sub-title">Ship visit target as per year ${actionBean.currentYear}</span>
                        <display:table class="tablecloth" name="${actionBean.listCounter}" requestURI="/shipVisit3Flow?detailStaffVisit" id="line" style="width:80%">
                            <display:column title="Staff Id" property="user.userId" />
                            <display:column title="Department" property="user.department.departmentName" />
                            <display:column title="Target Visit" property="target"/>
                            <display:column title="No. of visit" property="visited"/>
                            <display:column title="Total Balance"><c:out value="${line.target - line.visited}" /></display:column>                 
                        </display:table>
                    </div>
                    <c:if test="${actionBean.fromStage eq 'kiv'}">
                        <div id="page-title">
                            <span class="title">Ship Visit - Approval Form</span>
                        </div>
                    </c:if>
                    <c:if test="${actionBean.fromStage eq 'view'}">
                        <div id="page-title">
                            <span class="title">Ship Visit - View Form</span>
                        </div>
                        <s:button name="" value="Back" class="btn" onclick="back('${actionBean.staffSelected.userId}','${actionBean.statusDesc}','${actionBean.currentYear}');" />&nbsp;
                    </c:if>                    
                    <s:messages/>
                    <s:errors/>
                    <table border="0" align="center" width="70%">
                        <tr>
                            <td width="15%" class="tableHeader">Vessel Name :</td>
                            <td width="55%" class="tableValue">
                                ${actionBean.shipVisit3.vessel.vesselName}&nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td class="tableHeader">Date Visit :</td>
                            <td class="tableValue">
                                <fmt:formatDate value="${actionBean.shipVisit3.dateVisit}" pattern="dd/MM/yyyy"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="tableHeader">Location / Port :</td>
                            <td class="tableValue">
                                ${actionBean.shipVisit3.location}&nbsp;
                            </td>
                        </tr>
                        <c:forEach items="${actionBean.shipVisit3.listShipVisitSub}" var="object">
                            <tr>
                                <td class="tableHeader">${object.refShipVisitHeader.description} :</td>
                                <td class="tableValue">
                                    <c:if test="${empty(object.listSV3SubExtend)}">
                                            ${object.details}&nbsp;
                                    </c:if>
                                    <c:if test="${!empty(object.listSV3SubExtend)}">
                                        <fieldset>
                                            <div>
                                                <display:table class="tablecloth" name="${object.listSV3SubExtend}" requestURI="/shipVisit3Flow?detailStaffVisit" id="line2" >
                                                    <display:column title="Details" property="shipVisitSub.description" style="font-weight:bold;" />
                                                    <display:column title="Action">
                                                            <s:button name="" value="View..." class="btn" onclick="return popupWinSub('${line2.shipVisit3SubExtId}');"/>
                                                    </display:column>
                                                    <display:column title="Comments">
                                                            ${line2.details}&nbsp;
                                                    </display:column>
                                                </display:table>
                                            </div>
                                        </fieldset>
                                    </c:if>
                                </td>
                            </tr>
                        </c:forEach>
                        <tr>
                            <td class="tableHeader">Attachment/s :</td>
                            <td class="tableValue">
                                <s:button name="" value="View..." class="btn" onclick="return popupWin('${actionBean.shipVisit3Id}');"/>
                            </td>
                        </tr>
                    </table>
                    <br />
                </fieldset>
            </div>
            <c:if test="${actionBean.fromStage eq 'kiv'}">
                <div>
                    <fieldset>
                        <div id="page-title">
                            <span class="title">Remarks</span>
                        </div>
                        <p class="validateTips"><em>Note: </em>1) Approval must be choose either 'Approve' or 'Reject' before submit.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2) If Approval is 'Reject', 'Comment' must be filled before submit.</p>
                        <p>
                            <label>Approval :</label>
                            <s:radio id="status" name="statusApproval" value="A" />Approve &nbsp; <s:radio id="status" name="statusApproval" value="R" />Reject
                        </p>
                        <p>
                            <label>Comment :</label>
                            <s:textarea name="comment" id="rejectnote" rows="5" cols="50"/>
                        </p>
                        <p>
                            <label>&nbsp;</label>
                            <s:submit name="staffKIV" value="Back" class="btn" />&nbsp;&nbsp;&nbsp;<s:submit name="submitApproval" value="Submit" class="btn" onclick="return checkingSubmit();" />
                        </p>
                    </fieldset>
                </div>
            </c:if>
            <c:if test="${actionBean.fromStage eq 'view'}">
                <s:button name="" value="Back" class="btn" onclick="back('${actionBean.staffSelected.userId}','${actionBean.statusDesc}','${actionBean.currentYear}');" />&nbsp;
            </c:if>
            <div>
                <fieldset>
                    <div id="page-title">
                        <span class="title">History report</span>
                    </div>
                    <display:table class="tablecloth" name="${actionBean.shipVisit3.listHistory}" requestURI="/shipVisit3Flow?detailStaffVisit" id="line" style="width:50%">
                        <display:column title="No." ><center>${line_rowNum}.</center></display:column>
                        <display:column title="Status">
                            <c:if test="${line.status eq 'R'}">
                                Rejected
                            </c:if>
                            <c:if test="${line.status eq 'A'}">
                                Approved
                            </c:if>
                        </display:column>
                        <display:column title="Remarks" property="rejectNote" />
                        <display:column title="Date Approval" sortable="true"><fmt:formatDate value="${line.infoAudit.createDate}" pattern="dd/MM/yyyy hh:mm:ss a"/></display:column>
                        <display:column title="Approval By" sortable="true" property="verifierId.userId"/>
                    </display:table>                    
                </fieldset>
            </div>
        </s:form>
    </body>
</html>